import db from './db';
import logger from './logger';
import danmakuFilterTab from '../model/danmaku/danmakuFilterTab';

class settingHelper {
  private _useHEVC: boolean;
  private _useDASH: boolean;
  private _openDanmaku: boolean;
  private _notifyEnable: boolean;

  get notifyEnable() {
    return this._notifyEnable;
  }

  set notifyEnable(notifyEnable: boolean) {
    this._notifyEnable = notifyEnable;
    db.instance.update('notifyEnable', notifyEnable);
  }

  get useDASH() {
    return this._useDASH;
  }

  set useDASH(inUse: boolean) {
    this._useDASH = inUse;
    db.instance.update('useDASH', inUse);
  }

  get useHEVC() {
    return this._useHEVC;
  }

  set useHEVC(inUse: boolean) {
    this._useHEVC = inUse;
    db.instance.update('useHEVC', inUse);
  }

  get openDanmaku() {
    return this._openDanmaku;
  }

  set openDanmaku(isOpen: boolean) {
    this._openDanmaku = isOpen;
    db.instance.update('openDanmaku', isOpen);
  }

  addDanmakuFilter(type: number, oid: string, keyword: string) {
    try {

    } catch (e) {
      logger.error(e);
    }
  }

  removeDanmakuFilter(oid: string, type: number) {
    try {

    } catch (e) {
      logger.error(e);
    }
  }

  getDanmakuFilter(type: number = 0): Array<danmakuFilterTab> {
    let array: Array<danmakuFilterTab> = [];
    try {

    } catch (e) {
      logger.error(e);
    }
    return array;
  }

  init() {
    try {
      db.instance.query('notifyEnable').then((res) => {
        if (typeof res === 'boolean')
          this._notifyEnable = res;
        else
          this._notifyEnable = false;
      });
      db.instance.query('useDASH').then((res) => {
        if (typeof res === 'boolean')
          this._useDASH = res;
        else
          this._useDASH = false;
      });
      db.instance.query('useHEVC').then((res) => {
        if (typeof res === 'boolean')
          this._useHEVC = res;
        else
          this._useHEVC = false;
      });
      db.instance.query('openDanmaku').then((res) => {
        if (typeof res === 'boolean')
          this._openDanmaku = res;
        else
          this._openDanmaku = false;
      });
    } catch (e) {
      logger.error(e);
    }
  }
}
export default new settingHelper();